package com.itheima.publisher.config;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ReturnedMessage;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * Author:Cammy.Wu
 * Date:2024-05-28
 * Description:
 */

@Slf4j
@Configuration
@RequiredArgsConstructor
public class MQConfig {

    private final RabbitTemplate rabbitTemplate;

    @PostConstruct
    public void init() {
//        rabbitTemplate.setReturnsCallback(new RabbitTemplate.ReturnsCallback(){
        rabbitTemplate.setReturnsCallback(returnedMessage -> {
            log.error("监听到了消息return callback");
            log.debug("exchange:{}",returnedMessage.getExchange());
            log.debug("routingKey:{}",returnedMessage.getRoutingKey());
            log.debug("message:{}",returnedMessage.getMessage());
            log.debug("replyCode:{}",returnedMessage.getReplyCode());
            log.debug("replyText:{}",returnedMessage.getReplyText());
        });
    }
}
